package common.view;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;


public class IndentView extends JPanel
{
	private JTable table;
	private JTextField tfGenratedBy;
	private JTextField tfGeneratedDate;
	private JTextField tfIndentNo;
	private MaterialAdderView mAdder;
	private JTextField tfRequiredQty;
	private JComboBox cbProject;
	private JButton btnSave;
	private JButton btnCl;
	private JButton btnAdd;
	
	public IndentView() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
			
		JLabel lblGeneratedBy = new JLabel("Generated By :");
		springLayout.putConstraint(SpringLayout.WEST, lblGeneratedBy, 200, SpringLayout.WEST, this);
		lblGeneratedBy.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblGeneratedBy, 10, SpringLayout.NORTH, this);
		add(lblGeneratedBy);
		
		tfGenratedBy = new JTextField();
		tfGenratedBy.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfGenratedBy, 10, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, tfGenratedBy, 10, SpringLayout.EAST, lblGeneratedBy);
		add(tfGenratedBy);
		tfGenratedBy.setColumns(10);
		
		JLabel lblIndentNo = new JLabel("Indent No :");
		lblIndentNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblIndentNo, 10, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, lblIndentNo, 20, SpringLayout.EAST,tfGenratedBy);
		add(lblIndentNo);
		
		tfIndentNo = new JTextField();
		tfIndentNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, tfIndentNo,10, SpringLayout.EAST,lblIndentNo);
		//springLayout.putConstraint(SpringLayout.EAST, lblIndentNo, -6, SpringLayout.WEST, tfIndentNo);
		springLayout.putConstraint(SpringLayout.NORTH, tfIndentNo, 10, SpringLayout.NORTH,this);
		add(tfIndentNo);
		tfIndentNo.setColumns(10);
		
		JLabel lblCostCenter = new JLabel("Cost Center :");
		lblCostCenter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, lblCostCenter, 20, SpringLayout.EAST, tfIndentNo);
		springLayout.putConstraint(SpringLayout.NORTH, lblCostCenter, 10, SpringLayout.NORTH,this);
		add(lblCostCenter);
		
		JComboBox cbCostCenter = new JComboBox();
		cbCostCenter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		cbCostCenter.setPreferredSize(new Dimension(150, 23));
		springLayout.putConstraint(SpringLayout.NORTH, cbCostCenter, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, cbCostCenter, 10, SpringLayout.EAST, lblCostCenter);
		add(cbCostCenter);
		
		JLabel lblGenratedDate = new JLabel("Generated Date :");
		lblGenratedDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblGenratedDate, 25, SpringLayout.SOUTH, lblGeneratedBy);
		springLayout.putConstraint(SpringLayout.WEST, lblGenratedDate, 0, SpringLayout.WEST,lblGeneratedBy);
		add(lblGenratedDate);
		
		tfGeneratedDate = new JTextField();
		tfGeneratedDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfGeneratedDate, 0, SpringLayout.NORTH,lblGenratedDate);
		springLayout.putConstraint(SpringLayout.WEST, tfGeneratedDate, 10, SpringLayout.EAST,lblGenratedDate);
		add(tfGeneratedDate);
		tfGeneratedDate.setColumns(10);
		
		btnCl = new JButton("CL");
		btnCl.setActionCommand("GeneratedDate");
		btnCl.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnCl, 0, SpringLayout.NORTH, lblGenratedDate);
		springLayout.putConstraint(SpringLayout.WEST, btnCl, 10, SpringLayout.EAST, tfGeneratedDate);
		
		btnCl.setActionCommand("btnDate");
		add(btnCl);
		
		JLabel lblProjet = new JLabel("Project :");
		lblProjet.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblProjet, 0, SpringLayout.NORTH, lblGenratedDate);
		springLayout.putConstraint(SpringLayout.WEST, lblProjet, 20, SpringLayout.EAST,btnCl);
		add(lblProjet);
		
		cbProject = new JComboBox();
		cbProject.setPreferredSize(new Dimension(150, 23));
		cbProject.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, cbProject, 0, SpringLayout.NORTH,lblGenratedDate);
		springLayout.putConstraint(SpringLayout.WEST, cbProject, 20, SpringLayout.EAST,lblProjet);
		add(cbProject);
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.WEST, separator, 200, SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST,this);
		springLayout.putConstraint(SpringLayout.NORTH, separator, 20, SpringLayout.SOUTH,lblGenratedDate);
		add(separator);
		
		btnSave = new JButton("Save");
		btnSave.setActionCommand("Save");
		btnSave.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, btnSave, 200, SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.SOUTH, btnSave, -10, SpringLayout.SOUTH, this);
		add(btnSave);
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 20, SpringLayout.NORTH,separator);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 200, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -10, SpringLayout.NORTH,btnSave);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				" No.", "Item Code", "Item", "Item Specification", "Unit", "Requirement", "Balance", "Purchase"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, true, false, true, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(0).setPreferredWidth(45);
		table.getColumnModel().getColumn(3).setPreferredWidth(178);
		scrollPane.setViewportView(table);

		//********************************************************************************************
		
		mAdder = new MaterialAdderView();
		springLayout.putConstraint(SpringLayout.WEST,mAdder,10,SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.NORTH,mAdder,10,SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.EAST, mAdder, -10, SpringLayout.WEST,scrollPane);
		add(mAdder);
		
		JLabel lblRequiredQty = new JLabel("Required Qty");
		lblRequiredQty.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblRequiredQty, 20, SpringLayout.SOUTH, mAdder);
		springLayout.putConstraint(SpringLayout.WEST, lblRequiredQty, 10, SpringLayout.WEST,this);
		add(lblRequiredQty);
		
		tfRequiredQty = new JTextField();
		tfRequiredQty.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfRequiredQty, 6, SpringLayout.SOUTH,lblRequiredQty);
		springLayout.putConstraint(SpringLayout.WEST, tfRequiredQty, 10, SpringLayout.WEST,this);
		add(tfRequiredQty);
		tfRequiredQty.setColumns(10);
		
		btnAdd = new JButton("Add");
		btnAdd.setActionCommand("Add");
		btnAdd.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnAdd, 20, SpringLayout.SOUTH,tfRequiredQty);
		springLayout.putConstraint(SpringLayout.WEST, btnAdd, 10, SpringLayout.WEST, this);
		add(btnAdd);
	}
	
	public JTable getTable() {
		return table;
	}
	
	public void setTable(JTable table) {
		this.table = table;
	}
	
	public JTextField getTfGenratedBy() {
		return tfGenratedBy;
	}
	
	public void setTfGenratedBy(JTextField tfGenratedBy) {
		this.tfGenratedBy = tfGenratedBy;
	}
	
	public JTextField getTfGeneratedDate() {
		return tfGeneratedDate;
	}
	
	public void setTfGeneratedDate(JTextField tfGeneratedDate) {
		this.tfGeneratedDate = tfGeneratedDate;
	}
	
	public JTextField getTfIndentNo() {
		return tfIndentNo;
	}

	public void setTfIndentNo(JTextField tfIndentNo) {
		this.tfIndentNo = tfIndentNo;
	}
	public MaterialAdderView getmAdder() {
		return mAdder;
	}
	public JTextField getTfRequiredQty() {
		return tfRequiredQty;
	}
	public void setTfRequiredQty(JTextField tfRequiredQty) {
		this.tfRequiredQty = tfRequiredQty;
	}
	public JComboBox getCbProject() {
		return cbProject;
	}
	public void setCbProject(JComboBox cbProject) {
		this.cbProject = cbProject;
	}
	public void actionlisterners(ActionListener al)
	{
		btnAdd.addActionListener(al);
		btnCl.addActionListener(al);
		btnSave.addActionListener(al);
	}
}
